// main/discover/groupdetails/groupdetails.js
const { $Message } = require('../../../dist/base/index');
import drawQrcode from '../../../libs/weapp.qrcode.esm.js'
let app = getApp()
let utils = app.utils
Page({
    handleSuccess() {
        $Message({
            content: '成功复制',
            type: 'success'
        });
    },

    /**
     * 页面的初始数据
     */
    data: {
        item:{}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        
        var temp = JSON.parse(options.jsonStr);
        console.log(temp)
        var that = this
        that.setData({ item: temp.itme });
        var groupQR = temp.itme.groupQR 
        if (groupQR){
            drawQrcode({
                width: 120,
                height: 120,
                typeNumber: 9,
                foreground: '#585858',
                canvasId: 'myQrcode',
                text: temp.itme.groupQR
            })
        }

        var data = { 
            objectId: temp.itme.objectId 
        }
        console.log(data)
        app.request.browseGroupUpData(data).then(res => {
            console.log(res)
        }).catch(e => {
            console.error(e)
        })
    },

    handleClick: function (options) {
        console.log(this.data.item)
        if (this.data.item.groupWx == ''){
            $Message({
                content: '复制失败',
                type: 'error'
            });
        }else{
            wx.setClipboardData({
                data: this.data.item.groupWx,
                success: function (res) {
                    $Message({
                        content: '成功复制',
                        type: 'success'
                    });
                }
            })
        }
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
    
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
    
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
    
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
    
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
    
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
    
    }
})